﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MainClient
{
    public partial class frmKaitai : Form
    {
        private string opeator;
        public frmKaitai(string opeator, string tableName, string tableType, string cap, string tp)
        {
            InitializeComponent();
            this.opeator = opeator;
            this.lbl_tableID.Text = tableName;
            this.lbl_tableType.Text = tableType;
            this.lbl_capacity.Text = cap;
            this.lbl_tablePrice.Text = tp;
        }

        private void btn_addorder_Click(object sender, EventArgs e)
        {
            double dPayed = (this.txt_payed.Text.Trim() == "") ? 0d : double.Parse(this.txt_payed.Text.Trim());
            string orderID = new DataAccess.OrderDAO().addNewOrder(
                                            LoginUser.getCurrOper(),
                                            lbl_tableID.Text.Trim(), cb_waiterID.Text, dPayed);
            if (orderID == "")
            {
                Console.WriteLine("开台操作失败！");
                return;
            }
            Console.WriteLine("订单号："+orderID+", 开台操作成功!");
            
            frmDiancai formDiancai = new frmDiancai(opeator, lbl_tableID.Text, orderID);
            this.Visible = false;
            formDiancai.ShowDialog();
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmKaitai_Load(object sender, EventArgs e)
        {
            // Load waiterID from db.
            SqlConnection con = DataAccess.ConnectionManager.getInstance().getConnection();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select staffID from tb_staff", con);
            da.Fill(ds);
            this.cb_waiterID.DataSource = ds.Tables[0].DefaultView;
            this.cb_waiterID.DisplayMember = "staffID";
            this.cb_waiterID.Text = this.opeator;
        }                
    }
}
